


******FINALLY REGRESSION TIME***
use "table_g1.dta", clear

estimates clear

		
	*galtan
*no controls and no country dummies
eststo: reg galtan university ///
		, vce(cluster cntry2)
	
		estimates store galtan_nocontrols
	
*country dummies
eststo: reg galtan university ///
		i.cntry2, vce(cluster cntry2)
		
		estimates store galtan_dummies
		
**full list of controls
eststo: reg galtan university ///
		i.eiscedf i.eiscedm ///
		i.occf14b i.occm14b ///
		gndr agea ///
		i.cntry2, vce(cluster cntry2)
		
		estimates store galtan_controls

		
		esttab galtan* ///
		using "regressions_results_ci.csv", ///
		ci keep(university) replace
		
		esttab galtan* ///
		using "regressions_results.csv", ///
		t keep(university) replace
		
		
		translate @Results TableG1.txt, replace
		
		****Take the estimated coefficients now to save them in a csv file so that they can be graphed in Figure G1
		
			import delimited "regressions_results_ci.csv", stripquote(yes) clear /*this is only for the confidence intervals*/


keep in 4
foreach x of varlist _all{

	replace `x' = subinstr(`x',"=","",.)
	replace `x' = subinstr(`x',"[","",.)
	replace `x' = subinstr(`x',"]","",.)
	replace `x' = subinstr(`x',"*","",.)
}



***keep only the confidence intervals

drop v1
rename v2 nocontrols
rename v3 dummies
rename v4 allcontrols


foreach var of varlist _all{
split `var', p(",")
}
	
foreach var of varlist nocontrols1-allcontrols2{
gen new_`var'=real(`var')
}	

keep new* 
	
	rename new_nocontrols1 lower_nocontrols
	rename new_nocontrols2 upper_nocontrols
	rename new_dummies1 lower_dummies
	rename new_dummies2 upper_dummies
	rename new_allcontrols1 lower_allcontrols
	rename new_allcontrols2 upper_allcontrols
	
		xpose, clear varname
		split _varname, p("_")
		drop _varname
	reshape wide v1, i(_varname2) j(_varname1) string
	
	rename _v model
	rename v1l lower
	rename v1u upper
sort model
save "ci.dta", replace

***bring in the data on coefficients and t values
			import delimited "regressions_results.csv", stripquote(yes) clear /*this is only for the confidence intervals*/
keep in 3/5

foreach x of varlist _all{

	replace `x' = subinstr(`x',"=","",.)
	replace `x' = subinstr(`x',"[","",.)
	replace `x' = subinstr(`x',"]","",.)
	replace `x' = subinstr(`x',"*","",.)
	replace `x' = subinstr(`x',"(","",.)
	replace `x' = subinstr(`x',")","",.)

}

drop v1
foreach var of varlist _all{
gen new_`var'=real(`var')
}

rename new_v2 nocontrols
rename new_v3 dummies
rename new_v4 allcontrols

drop v*

		xpose, clear varname

		rename _varname model
		rename v1 coef
		rename v2 t_score
		rename v3 N
		
		sort model

merge model using "ci.dta"

drop _merge

export delimited using "G1_results.csv", replace	

		
